<?php

$db = new PGSQLConnector('u_superuser');

$idperson = null;
$phone = null;
$error = null;

if(isset($_POST['forgot'])) {
    $email = $_POST['email'];
    if($email != null) {
        if(!getIdpersonFromUsername($email)) $error = "Username don't exist.";
        else {
            $idperson = getIdpersonFromUsername($email);
            $phone = getPhone($idperson);
            if(!$phone) {
                //Send by email
            } else {
                $rs = setPassword($email,$phone, $sms);
                echo $rs;
            }
        }
    }
}

$template = newPage('forgot');
$template->title = 'Forgot password - IAESTE Application System';
$template->l = $l;
$template->error = $error;

try {
    echo $template->execute();
} catch(Exception $e) {
    echo $e;
}
?>
